<?php
require_once 'Zend/Auth.php';
$auth = Zend_Auth::getInstance();
if ($auth->hasIdentity()) {

$user=$auth->getIdentity()->id;
}else
{
    header("Location: /adm/login.php");
    
}
require('../class/sql.php');
require('../class/sitemap.php');

//   print_r($_POST);exit();
/*    $c = count($_FILES['pic']['name']);
    $id=22;
    for($i=0;$i<$c;$i++)
    {
        $name = "$id-$i-b";
        //resizes($_FILES['pic']['tmp_name'][$i],$name);
        $arr[] = $name.".jpg";
    }
    print_r($arr);
    $a = serialize($arr);
    echo $a;
    print_r(unserialize($a));
    echo "\n $i";
    exit();
*/
if(isset($_POST['id'])&&($_POST['id'] == 'new')&&(!empty($_POST['title'])))
{
    /*
    print_r($_POST);
    Array ( [title] => Главная [meta_key] => главная [meta_desc] => главная [date_post] => 2010-11-23 18:08:24 [index_page] => 1 [content] => Текст на главной [id] => 1
    */
    if(isset($_POST['index_page'])) $index_page = 1; else $index_page=0;
    $dates=date('Y:m:d G:i:s');
    $data = array(                  'title'=>$_POST['title'],
                                    'content'=>$_POST['content'],
                                    'url'=>$_POST['url'],
                                    'index_page'=>$index_page,
                                    'meta_desc'=>$_POST['meta_desc'],
                                    'user_id'=>$_POST['user_id'],
                                    'meta_key'=>$_POST['meta_key'],
                                    'date_post'=>$_POST['date_post']);
    $addpost = $db->insert('pages',$data);
    

}elseif(isset($_POST['id'])&&(!empty($_POST['title'])))
{
    //Array ( [title] => Четвертая запись [metro] => 2 [m_key] => без ключей [m_desc] => без деска [summ] => 5 000 [sq] => [info] => без текста [id] => 60 [type] => 60 )
    $dates=date('Y:m:d G:i:s');
    $data = array(                  'title'=>$_POST['title'],
                                    'content'=>$_POST['content'],
                                    'url'=>$_POST['url'],
                                    'index_page'=>$_POST['index_page'],
                                    'meta_desc'=>$_POST['meta_desc'],
                                    'meta_key'=>$_POST['meta_key'],
                                    'user_id'=>$_POST['user_id'],
                                    'date_post'=>$_POST['date_post']);

    $where = $db->quoteInto("id = ?",$_POST['id']);                                    
    $addpost = $db->update('pages',$data,$where);
}

$url = "http://".$_SERVER['HTTP_HOST']."/adm/index.php";
header("Location: $url");
?>